package com.chujian.framework.auth;

/**
 * @author ：chujian
 * @since ：2020-07-30
 * 访问者Holder
 */
public class AccessorHolder {

    private static final ThreadLocal<Accessor> ctx = new ThreadLocal<>();

    public static void setAccessor(Accessor accessor) {
        ctx.set(accessor);
    }

    public static Accessor getAccessor() {
        return ctx.get();
    }

    public static void clear() {
        ctx.remove();
    }

    public static Long getUserId() {
        return getAccessor().getUserId();
    }

    public static Long getProdId() {
        return getAccessor().getProdId();
    }

    public static Long getCompId() {
        Accessor accessor = ctx.get();
        if (accessor == null)
            return null;
        return accessor.getCompId();
    }

    public static Long getAcId() {
        Accessor accessor = ctx.get();
        if (accessor == null)
            return null;
        return accessor.getAcId();
    }
}
